
<template>
  <div class="authen">
    <div></div>
    <span>{{ tip }}</span>
  </div>
</template>

<script>
import Vue from "vue";
import { getAuthen } from "@/utils/getAuthen";
import querystring from "querystring";
import { mapMutations, mapActions } from "vuex";
import Parse from "@/utils/parse";

export default Vue.extend({
  head() {
    return {
      title: "解析",
    };
  },
  data() {
    return {
      redirect: "",
      tip: "解析中...",
    };
  },
  async created() {
    const phone = this.phone
    const parse = Parse.getInstance();
    let parseResult;
    try {
      parseResult = await parse.parseCode(this.$route.fullPath);
    } catch (error) {
      this.tip = "亲，网址错误~";
      return
    }
    console.log("parseResult", parseResult);
    if (parseResult.issueId) {
      $nuxt.$store.commit("parse/setIssueId", parseResult.issueId)
      this.$router.replace({
        path: "/" + this.enterpriseId + "/coupon/get/",
      });
      console.log('优惠券解析成功~');
    } else if (parseResult.labelId) {
    } else {
      this.tip = "网址错误";
    }

    // 这里可以写一些url的操作
    // 处理一些逻辑后，跳转对应页面
  },
  methods: {
    handleGoto() {
      this.$router.replace({
        path: this.redirect,
      });
    },
    havingAuthen() {
      if (!this.$route.query.code) {
        getAuthen();
      } else {
        this.$store
          .dispatch("authen/login", this.$route.query.code)
          .then((res) => {
            this.handleGoto();
          })
          .catch((res) => {
            alert(res);
            getAuthen();
          });
      }
    },
    ...mapMutations({
      setEnterpriseId: "authen/setEnterpriseId",
      setAppId: "authen/setAppId",
    }),
    ...mapActions({
      getAppId: "authen/getAppId",
    }),
  },
});
</script>

<style>
.authen {
  width: 100vw;
  height: 100vh;
  position: relative;
}
.authen div {
  position: absolute;
  top: 2.38rem;
  left: 2.7rem;
  width: 1.82rem;
  height: 2.16rem;
  background: url("")
    no-repeat 0 0;
  background-size: 100% 100%;
}
.authen span {
  position: absolute;
  top: 5.22rem;
  width: 7.5rem;
  text-align: center;
  height: 0.56rem;
  font-size: 0.4rem;
  font-weight: 550;
  color: #000000;
  line-height: 0.56rem;
  font-family: PingFangSC-Regular, PingFang SC;
}
</style>
